<template>
  <div class="iframe-container">
    <iframe :src="src" scrolling="auto" frameborder="0" class="frame" :onload="onloaded()" />
  </div>
</template>

<script>
export default {
  data() {
    return {
      src: `${process.env.VUE_APP_BASE_API}/druid/index.html`,
      loading: null
    }
  },
  watch: {
    $route: {
      handler(val, oldVal) {
        // 如果是跳转到嵌套页面，切换iframe的url
        this.resetSrc(this.src)
      }
    }
  },
  mounted() {
    this.resetSrc(this.src)
  },
  methods: {
    // 获取路径
    resetSrc(url) {
      this.src = url
      this.load()
    },
    load() {
      this.loading = this.$loading({
        lock: true,
        text: 'loading...',
        spinner: 'el-icon-loading',
        background: 'rgba(0, 0, 0, 0.5)',
        // fullscreen: false,
        target: document.querySelector('#main-container ')
      })
    },
    onloaded() {
      if (this.loading) {
        this.loading.close()
      }
    }
  }
}
</script>

<style lang="scss" scoped>
.iframe-container {
  position: absolute;
  top: 50px;
  left: 0px;
  right: 0px;
  bottom: 0px;
  .frame {
    width: 100%;
    height: 100%;
  }
}
</style>
